﻿''' <summary>
''' Dieses Menue dient dazu die KO-Listen fuer die Zufaelligen KO's zu erstellen.
''' </summary>
''' <remarks></remarks>
Public Class ObjektKORandomMenue
    Inherits ObjektFormMenue

    Dim KOCheckBoxen As New List(Of ObjektKOCheckBox)
    Const KOCheckboxenBreite As Integer = 76
    Dim LetzterModus As CommanderWarsGameModi = DataSettings.CommanderWarsGameModus
    Public Sub New()
        MyBase.New()

        If DataSettings.Verhaeltnis = Hauptmenue.Breitbild Then
            Objektverwalter.LoadHintergrund(DataSettings.Resourcenpfad + "Backgrounds\SAHintergrundGross.png")
        Else
            Objektverwalter.LoadHintergrund(DataSettings.Resourcenpfad + "Backgrounds\SAHintergrund.png")
        End If
        Dim I As Integer = 0
        Dim KOID As Integer = 0
        Dim Position As New Point(10, 10)
        Dim R As Integer
        Dim KOSInXRichtung As Integer = Math.DivRem(DataSettings.BildschirmBreite - 20, KOCheckboxenBreite, R)
        Position.X += R
        Dim KOList As String() = ObjektLadeklasse.GetRandomCOList(DataSettings.CommanderWarsGameModus)
        Dim XZahl As Integer = 0
        Dim Panel As New ObjektPanel2D(New Rectangle(0, 0, DataSettings.BildschirmBreite, DataSettings.BildschirmHoehe - 150), New PointF, 1, False)
        MyBase.NeuPanel(Panel)
        While KOID < Objektverwalter.GetKOLength()
            If Objektverwalter.GetKO(KOID).KOID <> "ZUFALL" Then
                If Not Hauptmenue.User.LockedCOs.Contains(Objektverwalter.GetKO(KOID).KOID) Then
                    Dim Checked As Boolean = False
                    If KOList.Contains(Objektverwalter.GetKO(KOID).KOID) Then Checked = True
                    KOCheckBoxen.Add(New ObjektKOCheckBox(Position, "CheckBox", KOID, New PointF, Checked, Panel))
                    XZahl += 1
                    If XZahl < KOSInXRichtung Then
                        Position.X += KOCheckboxenBreite
                    Else
                        Position.X = 10 + R
                        Position.Y += KOCheckboxenBreite
                        XZahl = 0
                    End If
                    I += 1
                End If
            End If
            KOID += 1
        End While

        NeuButton(DataSettings.BildschirmBreite / 2 - 54, DataSettings.BildschirmHoehe - 100, DataSettings.Resourcenpfad + "Objects\Button.png", "Optionen", New PointF(0.5#, 1))
        NeuButton(DataSettings.BildschirmBreite / 2 - 54, DataSettings.BildschirmHoehe - 130, DataSettings.Resourcenpfad + "Objects\Button.png", "Speichern", New PointF(0.5#, 1))

        NeuLabel(10, DataSettings.BildschirmHoehe - 100, New String() {Sprachconverter.Translate("Spielmodus") + " :"}, New PointF(0, 1))
        NeuDropDownMenue(150, DataSettings.BildschirmHoehe - 100, New String() {"Advance Wars", "Advance Wars 2", "Advance Wars DS", "Commander Wars", "Advance Wars DC", "Commander Wars 2"}, New PointF(0, 1))
        DropDownMenues(0).SetItem(DataSettings.CommanderWarsGameModus)
    End Sub
    Public Sub ChangeSpielmodus(ByVal Spielmodus As CommanderWarsGameModi)
        Dim KOList As String() = ObjektLadeklasse.GetRandomCOList(Spielmodus)
        For I = 0 To KOCheckBoxen.Count - 1
            If KOList.Contains(KOCheckBoxen(I).GetKO.KOID) Then
                KOCheckBoxen(I).Checked = True
            Else
                KOCheckBoxen(I).Checked = False
            End If
        Next
    End Sub
    Public Overrides Sub Frame()
        If DropDownMenues(0).GetItemNumber <> LetzterModus Then
            LetzterModus = DropDownMenues(0).GetItemNumber
            ChangeSpielmodus(LetzterModus)
        End If
    End Sub

    Public Overrides Sub IniMenue()

    End Sub

    Public Overrides Sub KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs)
        Select Case e.KeyCode
            Case Keys.Escape
                Hauptmenue.Ini(Hauptmenue.Formmodi.Optionen)
            Case Else
                KeyDownObjekte(sender, e)
        End Select
    End Sub

    Public Overrides Sub Malen()

        For Each KOBox In KOCheckBoxen
            KOBox.Malen()
        Next

        MyBase.ObjekteMalen()

    End Sub

    Public Overrides Sub MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
        Select Case e.Button
            Case Windows.Forms.MouseButtons.Left
                For Each KOBox In KOCheckBoxen
                    If KOBox.MouseDown(sender, e) Then
                        Exit For
                    End If
                Next
                checkMouseDownObjekte(ObjektMaus.XKoordinate, ObjektMaus.YKoordinate)
        End Select
    End Sub

    Public Overrides Sub MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
        MouseMoveObjekte(e.X, e.Y)
    End Sub

    Public Overrides Sub MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
        Select Case e.Button
            Case Windows.Forms.MouseButtons.Left
                For Each KOBox In KOCheckBoxen
                    If KOBox.MouseUp(sender, e) = "Geklickt" Then
                        Exit For
                    End If
                Next
                ButtonGeklicktLinks(checkMouseUPObjekte(ObjektMaus.XKoordinate, ObjektMaus.YKoordinate))
        End Select
    End Sub
    Public Sub ButtonGeklicktLinks(ByVal Effekt As String)
        If Effekt = Nothing Then
            Exit Sub
        End If
        Select Case Effekt.ToLower
            Case "optionen"
                Hauptmenue.Ini(Hauptmenue.Formmodi.Optionen)
            Case "speichern"
                SaveCOList()
        End Select
    End Sub
    Private Sub SaveCOList()
        Dim NewCOList As String = ""
        Dim Checked As Integer = 0
        For I = 0 To KOCheckBoxen.Count - 1
            If KOCheckBoxen(I).Checked Then
                Checked += 1
                NewCOList += KOCheckBoxen(I).GetKO.KOID + "|"
            End If
        Next
        If Checked > 2 Then
            Select Case LetzterModus
                Case CommanderWarsGameModi.AdvanceWars
                    Hauptmenue.User.SaveRandomCOList("COListAW", NewCOList)
                Case CommanderWarsGameModi.AdvanceWars2
                    Hauptmenue.User.SaveRandomCOList("COListAW2", NewCOList)
                Case CommanderWarsGameModi.AdvanceWarsDS
                    Hauptmenue.User.SaveRandomCOList("COListAWDS", NewCOList)
                Case CommanderWarsGameModi.CommanderWars
                    Hauptmenue.User.SaveRandomCOList("COListCoW", NewCOList)
                Case CommanderWarsGameModi.AdvanceWarsDC
                    Hauptmenue.User.SaveRandomCOList("COListAWDC", NewCOList)
                Case CommanderWarsGameModi.CommanderWars2
                    Hauptmenue.User.SaveRandomCOList("COListCoW2", NewCOList)
            End Select
            DataSettings.MySettingsIniSave()
        Else
            Cursor.Show()
            MessageBox.ShowMessageBox("Game couldn't save CO-List! A CO-List has to have two or more CO's! The last CO-List was choosen!", MsgBoxStyle.Critical, "Saving Error!")
            Cursor.Hide()
        End If
    End Sub
    Public Overrides Sub MouseWheel(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)

    End Sub

    Public Overrides Sub SetMausBild()
        ObjektMaus.Zustand = ObjektMaus.Zustaende.Menue
    End Sub

    Public Overrides Sub SprachEingabe(ByVal Eingabe As String)
        ButtonGeklicktLinks(Eingabe.ToLower)
    End Sub
    Public Overrides Sub Reset()
        For I = 0 To KOCheckBoxen.Count - 1
            KOCheckBoxen(I).RemoveHandles()
        Next
        KOCheckBoxen.Clear()
        MyBase.Reset()
    End Sub
    Public Overrides Sub ChangeWindowSize(ByVal PosChange As System.Drawing.Point)
        MyBase.ChangeWindowSizeObjekte(PosChange)
        'CheckBoxen neu anordnen
        Dim I As Integer = 0
        Dim Position As New Point(10, 10)
        Dim R As Integer
        Dim KOSInXRichtung As Integer = Math.DivRem(DataSettings.BildschirmBreite - 20, KOCheckboxenBreite, R)
        Position.X += R
        Dim XZahl As Integer = 0
        While I < KOCheckBoxen.Count

            KOCheckBoxen(I).ChangePosition(Position)

            XZahl += 1
            If XZahl < KOSInXRichtung Then
                Position.X += KOCheckboxenBreite
            Else
                Position.X = 10 + R
                Position.Y += KOCheckboxenBreite
                XZahl = 0
            End If
            I += 1
        End While
    End Sub

    Public Overrides Sub KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs)

    End Sub
End Class
